﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class QuiDinhHangHoaDAO
    {

        public static List<QuiDinhHangHoa> LayDS()
        {
            try
            {
                QLSTLinqDataContext rv = new QLSTLinqDataContext();
                List<QuiDinhHangHoa> temp = new List<QuiDinhHangHoa>();
                var query = from c in rv.QuiDinhHangHoas
                            select c;
                temp = query.ToList();
                return temp;
            }
            catch
            {
                return null;
            }
        }


        public static bool Sua(QuiDinhHangHoa aCT)
        {
            try
            {
                QLSTLinqDataContext rv = new QLSTLinqDataContext();
                var query =
    (from ord in rv.QuiDinhHangHoas
    where ord.Id == aCT.Id
    select ord).First();

                query.SoLuongKhoMax = aCT.SoLuongKhoMax;
                query.SoLuongKhoMin = aCT.SoLuongKhoMin;
                query.SoLuongQuayMax = aCT.SoLuongQuayMax;
                query.SoLuongQuayMin = aCT.SoLuongQuayMin;

                rv.SubmitChanges();


                return true;
            }
            catch
            {
                return false;
            }
        }

        public static QuiDinhHangHoa hienThongTin(int ma)
        {
            try
            {
                QuiDinhHangHoa temp = new QuiDinhHangHoa();
                QLSTLinqDataContext rv = new QLSTLinqDataContext();
                var query = from c in rv.QuiDinhHangHoas
                            where c.IdMaHH == ma
                            select c;

                temp = query.First();

                return temp;


            }
            catch
            {
                return null;
            }
        }

        public static bool Xoa(int maCT)
        {
            try
            {
                QLSTLinqDataContext rv = new QLSTLinqDataContext();
                var cust =
    (from c in rv.QuiDinhHangHoas
     where c.IdMaHH == maCT
     select c).First();

                rv.QuiDinhHangHoas.DeleteOnSubmit(cust);
                rv.SubmitChanges();


                
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
